﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/admin.master" AutoEventWireup="true"
    CodeFile="inventory-report.aspx.cs" Inherits="admin_inventory_report" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Namespace="ECommerce.Library.Web" TagPrefix="ucc" %>
<%@ Register Src="~/controls/wucAdminValidator.ascx" TagName="AdminValidator" TagPrefix="wuc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="AdminHeaderContent" runat="Server">
    <script type="text/javascript">
        var QTY_Renderer = function (value, p, record, rowIndex) {
            if (value == "") {
                //alert(rowIndex);
                return String.format("<a href='#' onclick='BeginEditing({0})' class='leftlink'>Insert Quantity</a>", rowIndex);
            }
            else {
                return value;
            }
        };

        var BeginEditing = function (rowIndex) {
            if (categoryGrid != null) {
                var grid = categoryGrid;
                grid.getRowEditor().stopEditing();
                grid.getView().refresh();
                //            grid.getSelectionModel().selectRow(rowIndex);
                grid.getRowEditor().startEditing(rowIndex);
            }
        };

        var CommandHandler = function (command, rowIndex, grid) {
            //showObj(grid);
            grid.getRowEditor().stopEditing();
            grid.getView().refresh();
            grid.getSelectionModel().selectRow(rowIndex);
            grid.getRowEditor().startEditing(rowIndex);
        }

        var afterEdit = function (e) {

            e.grid.stopEditing();
            var QTY = $("#<%= txtQTY.ClientID %>").val();
            // Call DirectMethod
            Polana.WebService.UpdateInventory(e.record.data.InventoryId, QTY);
        };
        var categoryGrid;
        var ExportExcell = function () {
            Polana.WebService.ExportExcell();
        }
        var InsertNew = function () {
            Polana.WebService.InsertNew();
        }

        var onDocumentReady = function (grid) {
            categoryGrid = grid;
        }
    </script>
    <style type="text/css">
        .x-form-text
        {
            height: 16px !important;
            width: 100px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMiddleContent" runat="Server">
    <ext:ResourceManager ID="ScriptManager1" runat="server" Theme="Gray">
        <Listeners>
            <DocumentReady Fn="onDocumentReady(#{GridPanel1})" />
        </Listeners>
    </ext:ResourceManager>
    <ext:Store ID="Store1" runat="server" RemoteSort="true" OnRefreshData="Store1_RefreshData">
        <AutoLoadParams>
            <ext:Parameter Name="sort" Value="InventoryId desc" Mode="Value" />
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="100" Mode="Raw" />
        </AutoLoadParams>
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="InventoryId">
                <Fields>
                    <ext:RecordField Name="InventoryId" />
                    <ext:RecordField Name="ProductName" ServerMapping="ProductName" />
                    <ext:RecordField Name="ItemNumber" ServerMapping="ItemNumber" />
                    <ext:RecordField Name="Price" ServerMapping="Price" />
                    <ext:RecordField Name="QTY" />
                    <ext:RecordField Name="CostValue">
                    </ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <div class="admin-function-top inline">
        <ucc:ResponseMessage ID="uccResponseMessage" runat="server"></ucc:ResponseMessage>
        <ext:GridPanel ID="GridPanel1" runat="server" EnableViewState="true" AutoHeight="true"
            StoreID="Store1">
            <ColumnModel>
                <Columns>
                    <ext:Column Header="Product Name" DataIndex="ProductName" Resizable="false" Width="350"
                        Align="Left">
                    </ext:Column>
                    <ext:Column Header="Item Number" DataIndex="ItemNumber" Width="50">
                    </ext:Column>
                    <ext:Column Header="Price" DataIndex="Price" Width="50" Align="Right">
                        <Renderer Format="UsMoney" />
                    </ext:Column>
                    <ext:Column Width="80" DataIndex="QTY" Sortable="false" Align="Right">
                        <Renderer Fn="QTY_Renderer" />
                        <Editor>
                            <ext:TextField ID="txtQTY" runat="server" EmptyText="QTY" />
                        </Editor>
                    </ext:Column>
                    <ext:Column Header="Cost Value" DataIndex="CostValue" Width="50" Align="Right">
                        <Renderer Format="UsMoney" />
                    </ext:Column>
                </Columns>
            </ColumnModel>
            <TopBar>
                <ext:Toolbar ID="SearchToolbar2" runat="server" AutoScroll="true">
                    <Items>
                        <ext:Button ID="btnToolbarNewInsert" runat="server" Text="New Report" Icon="ApplicationFormDelete">
                            <Listeners>
                                <Click Handler="InsertNew();" />
                            </Listeners>
                        </ext:Button>
                        <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="750px" />
                        <ext:Button ID="btnToolbarExport" runat="server" Text="Export Report" Icon="ApplicationViewIcons">
                            <Listeners>
                                <Click Handler="ExportExcell();" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <BottomBar>
                <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="100" DisplayInfo="true"
                    DisplayMsg="Displaying orders {0} - {1} of {2}" EmptyMsg="No orders to display"
                    AutoWidth="true" />
            </BottomBar>
            <LoadMask ShowMask="true" />
            <Plugins>
                <ext:RowEditor ID="rowedi" runat="server" SaveText="Update" ClicksToEdit="2" ErrorSummary="true"
                    ShowTooltip="={Ext.emptyFn}">
                    <Listeners>
                        <AfterEdit Fn="afterEdit" />
                    </Listeners>
                </ext:RowEditor>
            </Plugins>
            <Listeners>
                <Command Handler="CommandHandler(command, rowIndex, this)" />
            </Listeners>
            <View>
                <ext:GridView ID="GridView1" runat="server" ForceFit="true">
                </ext:GridView>
            </View>
        </ext:GridPanel>
    </div>
    <script type="text/javascript">
        Ext.override(Ext.grid.GridView, {
            getEditorParent: function () {
                return document.body;
            }
        });
    </script>
</asp:Content>
